

if modifier_courier == nil then modifier_courier = class({}) end

if modifier_courier_speed_gains == nil then modifier_courier_speed_gains = class({}) end
LinkLuaModifier("modifier_courier_speed_gains", "abilities/modifier_courier", LUA_MODIFIER_MOTION_NONE )


function modifier_courier_speed_gains:GetBehavior()
    return DOTA_ABILITY_BEHAVIOR_PASSIVE
end

function modifier_courier_speed_gains:IsPurgable()
    return false
end

function modifier_courier_speed_gains:IsHidden()
    return false
end

function modifier_courier_speed_gains:DeclareFunctions()
    return {
        MODIFIER_PROPERTY_ATTACKSPEED_BONUS_CONSTANT,
        MODIFIER_EVENT_ON_ATTACK_START,
    }
end

function modifier_courier_speed_gains:GetModifierAttackSpeedBonus_Constant()
    return 5650
end

function modifier_courier_speed_gains:OnAttackStart(params)
    if IsServer() then
        if params.attacker~=self:GetParent() then return end
        if not (params.target.GetName and params.target:GetName()=="npc_dota_courier") then
            self:GetParent():RemoveModifierByName("modifier_courier_speed_gains")
        end
    end
end


function modifier_courier:CheckState()
    local state = {
        [MODIFIER_STATE_COMMAND_RESTRICTED] = true,
        [MODIFIER_STATE_ROOTED] = true,
        [MODIFIER_STATE_MAGIC_IMMUNE] = true
    }
    return state
end

function modifier_courier:GetBehavior()
    return DOTA_ABILITY_BEHAVIOR_PASSIVE
end

function modifier_courier:DeclareFunctions()
    return {
        MODIFIER_PROPERTY_TOTAL_CONSTANT_BLOCK,
    }
end

function modifier_courier:GetModifierTotal_ConstantBlock(keys)
    local attacker = keys.attacker
    if attacker:IsRealHero() then
        local gold=1
        local heal=attacker:GetMaxHealth()*0.05
        local mana=attacker:GetMaxMana()*0.05
        attacker:ModifyCustomGold(gold)
        attacker:Heal(heal,attacker)
        attacker:GiveMana(mana)
        SendOverheadEventMessage(PlayerResource:GetPlayer(attacker:GetPlayerID()), OVERHEAD_ALERT_DAMAGE, self:GetParent(), 1, nil )
        SendOverheadEventMessage(PlayerResource:GetPlayer(attacker:GetPlayerID()),OVERHEAD_ALERT_GOLD, attacker, gold, nil)
        SendOverheadEventMessage(nil,OVERHEAD_ALERT_HEAL, attacker, heal, nil)
        SendOverheadEventMessage(nil,OVERHEAD_ALERT_MANA_ADD, attacker, mana, nil)

        attacker:AddNewModifier(attacker, nil, "modifier_courier_speed_gains", {duration=3})
    end
    return (keys.damage-1)
end

function modifier_courier:GetIntrinsicModifierName ()
    return "modifier_ghost_fate"
end

function modifier_courier:IsPurgable()
    return false
end

function modifier_courier:IsHidden()
    return true
end


